package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 添加或更新供应商
     * @param supplier
     * @return
     */
    @PostMapping("save")
    public ServiceVO save(Supplier supplier){
        this.supplierService.save(supplier);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 分页查询供应商
     * @param page
     * @param rows
     * @param supplierName
     * @return
     */
    @PostMapping("list")
    public Map<String,Object> querySupplierByPage(Integer page, Integer rows, String supplierName) {
        return this.supplierService.list(page,rows,supplierName);
    }

    @PostMapping("delete")
     public ServiceVO delete(String ids){
        return this.supplierService.delete(ids);
    }
}
